package org.example.lethear.entity;

import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

/**
 * 点赞实体类
 */
@Entity
@Table(name = "likes")
@Data
@EqualsAndHashCode(callSuper = false)
@EntityListeners(AuditingEntityListener.class)
public class Like {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @Column(name = "user_id", nullable = false)
    private Long userId;
    
    @Column(name = "target_id", nullable = false)
    private Long targetId;
    
    @Column(name = "target_type", nullable = false)
    private Integer targetType; // 1-帖子，2-评论
    
    @CreatedDate
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;
    
    // 构造方法
    public Like() {}
    
    public Like(Long userId, Long targetId, Integer targetType) {
        this.userId = userId;
        this.targetId = targetId;
        this.targetType = targetType;
    }
    
    // 常量定义
    public static final int TYPE_POST = 1;
    public static final int TYPE_COMMENT = 2;
    
    public String getTargetTypeName() {
        if (targetType == null) return "未知";
        return switch (targetType) {
            case TYPE_POST -> "帖子";
            case TYPE_COMMENT -> "评论";
            default -> "未知";
        };
    }
} 